package com.jy.api.domain;

import com.jy.api.signUpReq.stock.InventoryInReq;
import com.jy.api.signUpReq.stock.StockBarReq;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.util.Date;

/**
 * 出入库单，一般用于记录店铺与供应商的交互。 店铺内的出入库（比如仓库到吧台，吧台销售出库等）不生成出入库单。
 * <p>
 * Created by lihu on 2018/1/31.
 */
@Entity
@Data
@NoArgsConstructor
@Table(uniqueConstraints = @UniqueConstraint(name = "UK_STOCK_RECEIPT", columnNames = {"code"}))
public class StockReceipt {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long id;

    private String code;

    @Column(length = 50)
    private String storeId;

    /**
     * 操作人
     */
    private String operatorId;

    private String operatorName;

    /**
     * 金额
     */
    private double amount;

    /**
     * 数量
     */
    private int quantity;

    /**
     * 单据图片地址
     */
    private String receiptFileURL;

    /**
     * 备注
     */
    private String notes;


    /**
     * 出入库原因
     */
    @Enumerated(EnumType.STRING)
    private StockChangeReason stockSource;

    /**
     * 出入库
     */
    @Enumerated(EnumType.STRING)
    private StockType type;

    /**
     * 辨识是仓库还是吧台
     */
    @Enumerated(EnumType.STRING)
    private StockLevel level;
    @Column(insertable = false, updatable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date addTime;


    public StockReceipt(InventoryInReq inReq, StockType type) {
        this.code = inReq.getCode();
        this.storeId = inReq.getStoreId();
        this.operatorId = inReq.getOperatorId();
        this.operatorName = inReq.getOperatorName();
        this.amount = inReq.getTotalAmount();
        this.quantity = inReq.getCountNum();
        this.receiptFileURL = inReq.getReceiptFileURL();
        this.notes = inReq.getNotes();
        this.stockSource = inReq.getStockSource();
        this.type = type;
        this.level=StockLevel.WAREHOUSE;
    }



    public StockReceipt(StockBarReq inReq, StockType type) {
        this.code = inReq.getCode();
        this.storeId = inReq.getStoreId();
        this.operatorId = inReq.getEmpId();
        this.operatorName = inReq.getOperatorName();
        this.amount = inReq.getAmount();
        this.quantity = inReq.getSkuCount();
        this.notes = inReq.getNotes();
        this.type = type;
        this.level=StockLevel.BAR;
    }


}
